var queingAlarm = 0;
var map;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function alarm(str){
	var htmlStr = "<div class='ui-widget'><div class='ui-state-highlight ui-corner-bottom' style='margin:2px; padding: .7em .7em;'>"; 
	htmlStr += "<p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>";
	htmlStr += "<strong>"+str+"</strong></p></div></div>";
	$("#alarmLayer").html(htmlStr).hide();
	$("#alarmLayer").slideDown(200);
	queingAlarm++;
	setTimeout('closeAlarm()',2300);
}

function closeAlarm(){
	if(--queingAlarm==0){
		$("#alarmLayer").slideUp(500);
	}
}

function Popup(url,target,flag){
	var openObj = window.open(url,target,flag,false);
}

function getTwitterAuthPage(currentWebRoot){
	Popup(currentWebRoot+"/auth.trav?action=toauthpage","_blank","width=850,height=450");
}

function authComplete(currentWebRoot){
	location.href = currentWebRoot;
}
function getDatePost(currentWebRoot,date,seq){
	$.ajax({
		  url: currentWebRoot+"/post.jsp?date="+date+"&seq="+seq,
		  success: function(data) {
			Sexy.info(data);
		  }
		});
	
}
var infowindowArray = [];  
var markersArray = []; 
var prevIndex = 0;
var currentIndex = 0;
 function initialize() {
	  
	  var points = [];
	  var clickCounter = 1;

	  directionsDisplay = new google.maps.DirectionsRenderer();
	  
	  
   var latlng = new google.maps.LatLng(37.565100,126.989550);//서울로 시작
   var myOptions = {
     zoom: 5,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
   directionsDisplay.setMap(map);

   /*
   google.maps.event.addListener(map, 'click', function(event) {
       placeMarker(event.latLng);
     });
    */
   
	function placeMarker(location,content) {		    	
	  var marker = addMarker(location);
	  
	  map.setCenter(location);
	  var infowindow = new google.maps.InfoWindow({
	        content: content
	    	});
	  infowindowArray.push(infowindow);
      //infowindow.open(map,marker);
	  prevIndex++;
	}

	

	function addMarker(location) {
	  marker = new google.maps.Marker({
	    position: location,
	    map: map
	  });
	  markersArray.push(marker);
	  return marker;
	}

	// Removes the overlays from the map, but keeps them in the array
	function clearOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(null);
	    }
	  }
	}

	// Shows any overlays currently in the array
	function showOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(map);
	    }
	  }
	}

	// Deletes all markers in the array by removing references to them
	function deleteOverlays() {
	  if (markersArray) {
	    for (i in markersArray) {
	      markersArray[i].setMap(null);
	    }
	    markersArray.length = 0;
	  }
	}

	function calcRoute() {
		  var start = document.getElementById("start").value;
		  var end = document.getElementById("end").value;
		  var request = {
		    origin:start, 
		    destination:end,
		    travelMode: google.maps.DirectionsTravelMode.DRIVING
		  };
		  directionsService.route(request, function(result, status) {
		    if (status == google.maps.DirectionsStatus.OK) {
		      directionsDisplay.setDirections(result);
		    }
		  });
		}
	
		
 }
